#!/usr/bin/python
# -*- coding: utf-8 -*-
#创建SocketServerTCP服务器：
#本代码来自所出售产品的淘宝店店主编写
#未经受权不得复制转发
#淘宝店：https://fengmm521.taobao.com/
#再次感谢你购买本店产品
import time

LEFTDOWN = '21'     #左键按下
RIGHTDOWN = '23'    #右键按下
ALLUP     = '20'    #按键抬起

class _eventObj():
    def __init__(self,dtype,pdat):
        self.tp = dtype   #接收到的数据类型,1为鼠标坐标,2为键盘按下值
        self.dat = pdat

que = None

PWH = [1080,1920]

def sendCmd(cmd):
    cmd += '\n'
    eobj = _eventObj(None,cmd)
    que.put(eobj)


def initCmdUtil(q,):
    global que
    que = q

def set_screenWH(x,y):
    global PWH
    PWH[0] = x
    PWH[1] = y
    tcmd = '10,%d,%d'%(PWH[0],PWH[1])
    print(tcmd)
    sendCmd(tcmd)

def release(x,y):
    if not que:
        print('erro:not init cmd Queue')
    tcmd = '2,%d,%d'%(x,y)
    sendCmd(tcmd)
    return [tcmd,int(time.time()*1000)]
def press(x,y):
    if not que:
        print('erro:not init cmd Queue')
    tcmd = '1,%d,%d'%(x,y)
    sendCmd(tcmd)
    return [tcmd,int(time.time()*1000)]
def click(x,y):
    tcmd = '3,%d,%d'%(x,y)
    sendCmd(tcmd)
    return [tcmd,int(time.time()*1000)]

#按下点击笔并滑动到指定坐标x,y,然后抬起点击笔,l为按下移动的跑离,(x,y)按下后要移动到的坐标
def slide(p1,p2,ptime = 1000):
    if not que:
        print('erro:not init cmd Queue')
    tcmd = '4,%d,%d,%d,%d,%d'%(p1[0],p1[1],p2[0],p2[1],ptime)
    # sendCmd(tcmd)
    return [tcmd,int(time.time()*1000)]

#主函数,程序从这里开始运行
def main():
    pass
    
if __name__ == '__main__':
    main()
    # test()


